package com.guanghua.brick.html.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.guanghua.brick.html.IDataSource;
import com.guanghua.brick.html.WebControl;

public class CoreIfTag extends BodyTagSupport {
	
	//private static Log logger = LogFactory.getLog(CoreIteratorTag.class);
	
	private String id = null;
	private Boolean test = true;
	private String testSource = null;
	
	public int doStartTag() throws JspException {
		
		if (this.test == null && this.testSource != null) {
			IDataSource ds = WebControl.getDataSourceParser(pageContext);
			this.test = (Boolean) ds.parseDataSource(pageContext, this.testSource, Boolean.class);
		}
		
		pageContext.getRequest().setAttribute(this.id, test);
		
		if (this.test) {
			return BodyTagSupport.EVAL_BODY_INCLUDE;
		} else {
			return BodyTagSupport.SKIP_BODY;
		}
	}

	public Boolean getTest() {
		return test;
	}

	public void setTest(Boolean test) {
		this.test = test;
	}

	public String getTestSource() {
		return testSource;
	}

	public void setTestSource(String testSource) {
		this.testSource = testSource;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
}
